home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / graphics / gif2rpc / source / 8bpp / c / nearest < prev    next >
Encoding:
Text File  |  1995-10-16  |  1.6 KB  |  69 lines

  1. /* nearest.c
  2.  * AUTHOR:      Cy Booker, cy@cheepnis.demon.co.uk
  3.  * LICENSE:     FreeWare, Copyright (c) 1995 Cy Booker
  4.  */
  5.  
  6. #include "internal.h"
  7.  
  8. #include <assert.h>
  9.  
  10. #include "OS:macros.h"
  11. #include "OS:hourglass.h"
  12.  
  13.  
  14.  
  15. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  16.  */
  17.  
  18. extern bool process_gif_8bpp_nearest(
  19.                 const process_gif       *p) {
  20.   bits  *rove;
  21.   bits  dest;
  22.   int   width, height;
  23.   int   x, y;
  24.   int   line_length;
  25.   bits  t;
  26.   bits  pixtrans[256];
  27.  
  28.   assert(p);
  29.   assert(p->pixel_width > 0);
  30.   assert(p->pixel_height > 0);
  31.   assert((p->line_length & 3) == 0);
  32.   assert(p->fn);
  33.   assert(p->in_palette.ncolours < COUNT(pixtrans));
  34.   assert(p->out_palette.colours);
  35.  
  36.   process_gif_calc_pixtrans(p, pixtrans);
  37.   
  38.   /*
  39.    * not we pre-load values from the process_gif array
  40.    * because it considerably helps the compiler produce better code
  41.    */
  42.   rove = (bits *)p->buffer;
  43.   height = p->pixel_height;
  44.   width = ((p->pixel_width + 3) & ~3) >> 2;
  45.   line_length = p->line_length >> 2;
  46.   
  47.   for (y= p->pixel_height; (y > 0); y--) {
  48.     if ((y & 7) == 0) {
  49.       xhourglass_percentage((y * 100) / height);
  50.     }
  51.     for (x= width - 1; (x >= 0); x--) {
  52.       /*
  53.        * reading/writing one 32-bit word is much faster than four bytes
  54.        */
  55.       t = rove[x];
  56.       dest  = pixtrans[(t << (3*8)) >> 24] << (0*8);
  57.       dest |= pixtrans[(t << (2*8)) >> 24] << (1*8);
  58.       dest |= pixtrans[(t << (1*8)) >> 24] << (2*8);
  59.       dest |= pixtrans[(t << (0*8)) >> 24] << (3*8);
  60.       rove[x] = dest;
  61.     }
  62.     rove += line_length;
  63.   }
  64.   return FALSE;
  65. }
  66.  
  67.  
  68.  
  69.